"""
    @TODO session工具类
"""


def get_session(request, keyword):
    """
    获取session
    :param request:
    :param keyword:
    :return:
    """
    return request.session[keyword]


def exists_session(request, keyword):
    """
    session 是否存在
    :param request:
    :param keyword:
    :return:
    """
    exists = False
    try:
        info = request.session[keyword]
        if info is not None:
            exists = True
    except Exception as ex:
        pass
    return exists


def clear_session(request, keyword):
    """
    清除session
    :param request:
    :param keyword:
    :return:
    """
    if exists_session(request, keyword):
        request.session.delete(keyword)


def create_session(request, keyword, content):
    """
    创建session
    :param request:
    :param keyword:
    :param content:
    :return:
    """
    clear_session(request, keyword)
    request.session[keyword] = content
